package test.wym;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

public class UserBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

	@Override
	protected Class<?> getBeanClass(Element element) {
		return User.class;
	}


	@Override
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String name = element.getAttribute("name");
		String age = element.getAttribute("age");
		String sex = element.getAttribute("sex");

		if(StringUtils.hasText(name)){
			builder.addPropertyValue("name", name);
		}

		if(StringUtils.hasText(age)){
			builder.addPropertyValue("age", age);
		}

		if(StringUtils.hasText(sex)){
			builder.addPropertyValue("sex", sex);
		}
	}




}
